package com.ruangong.GitClient.app;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.media.Image;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.ruangong.GitClient.HunHePanAPI.MovieLink;
import com.ruangong.GitClient.R;
public class ResourceDetails extends AppCompatActivity {
    private TextView textDiskName;
    private TextView textShareName;
    private TextView textDiskType;
    private TextView textViewLinkValue;

    private MovieLink link;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_resource_details);

        // 初始化 TextView 和 Button
        textDiskName = findViewById(R.id.textDiskName);
        textShareName = findViewById(R.id.textShareName);
        textDiskType = findViewById(R.id.textDiskType);
        textViewLinkValue = findViewById(R.id. textViewLinkValue);

        ImageButton copyLinkButton = findViewById(R.id.buttonCopyLink);


        // 从 Intent 中获取传递的密码对象
        link = (MovieLink) getIntent().getSerializableExtra("MOVIE_LINK");

        // 如果密码对象有效，则显示在界面上
        if (link != null) {
            // 将密码信息显示在相应的 TextView 中
            String diskName = android.text.Html.fromHtml(link.getDiskName()).toString();
            String shareName = android.text.Html.fromHtml(link.getShareUser()).toString();
            String diskType = android.text.Html.fromHtml(link.getDiskType()).toString();
            String linkValue = android.text.Html.fromHtml(link.getLink()).toString();

            textDiskName.setText(diskName);
            textShareName.setText(shareName);
            textDiskType.setText(diskType);
            textViewLinkValue.setText(linkValue);
        }

        //设置复制链接按钮的点击事件监听器
        copyLinkButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 复制账号到剪贴板
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("link", link.getLink());
                clipboard.setPrimaryClip(clip);

                // 提示复制成功
                Toast.makeText(ResourceDetails.this, "链接已复制到剪贴板", Toast.LENGTH_SHORT).show();
            }
        });


    }
}